<?php
/**
 * 计数器
 */
class HelperCounter extends CController{
	
    /**
     * 某一个分类的文章数
     * @param type $typeId
     * @return type
     */
    static public function blogSum($typeId){
        $criteria=new CDbCriteria();
        $criteria->order = 'create_date DESC';
        $criteria->condition = 'type_id = :type_id';
        $criteria->params = array(':type_id'=>$typeId);
        $blog = Blog::model()->findAll($criteria);
        
        return count($blog);
    }
    
    /**
     * 某一个分类的文章总浏览数
     * @param type $typeId
     * @return type
     */
    static public function blogReadSum($typeId){
        $criteria=new CDbCriteria();
        $criteria->order = 'create_date DESC';
        $criteria->condition = 'type_id = :type_id';
        $criteria->params = array(':type_id'=>$typeId);
        $blog = Blog::model()->findAll($criteria);
        
        $read_sum = 0;
        foreach($blog as $k=>$v){
            $read_sum += $v->read_sum;
        }
        return  $read_sum;
    }
    
    /**
     * 某个分类的文件的总数
     * @param type $typeId
     * @return type
     */
    static public function fileSum($typeId){
        $criteria=new CDbCriteria();
        $criteria->order = 'create_date DESC';
        $criteria->condition = 'category_id = :category_id';
        $criteria->params = array(':category_id'=>$typeId);
        $file = File::model()->findAll($criteria);
        
        return count($file);
    }
    
    /**
     * 某个分类的文件下载总数
     * @param type $typeId
     * @return type
     */
    static public function fileDownloadSum($typeId){
        $criteria=new CDbCriteria();
        $criteria->order = 'create_date DESC';
        $criteria->condition = 'category_id = :category_id';
        $criteria->params = array(':category_id'=>$typeId);
        $file = File::model()->findAll($criteria);
        
        $download_sum = 0;
        foreach($file as $k=>$v){
            $download_sum += $v->download_sum;
        }
        return  $download_sum;
    }
    
    /**
     * 某个分类的链接数
     * @param type $typeId
     * @return type
     */
    static public function linkSum($typeId){
        $criteria=new CDbCriteria();
        $criteria->order = 'create_date DESC';
        $criteria->condition = 'category_id = :category_id';
        $criteria->params = array(':category_id'=>$typeId);
        $link = Link::model()->findAll($criteria);
        
        return count($link);
    }
    
    /**
     * 某个角色的用户数
     * @param type $typeId
     * @return type
     */
    static public function userSum($typeId){
        $criteria=new CDbCriteria();
        $criteria->order = 'create_date DESC';
        $criteria->condition = 'role_id = :role_id';
        $criteria->params = array(':role_id'=>$typeId);
        $user = User::model()->findAll($criteria);
        
        return count($user);
    }
}